#include <iostream>
#include "../material/StrVec.hpp"
using namespace std;

// 简单辅助函数，用于打印 StrVec 状态
void printStrVec(const StrVec &v, const string &name) {
    cout << name << " [size=" << v.size() << " capacity=" << v.capacity() << "] : ";
    for (auto p = v.begin(); p != v.end(); ++p)
        cout << *p << " ";
    cout << "\n";
}

// 用于返回局部对象测试移动构造
StrVec make_vec() {
    return StrVec(); // 临时对象，右值
}

int main() {
    cout << "=== Test 1: default constructor + push_back ===\n";
    StrVec v1;
    v1.push_back("hello");
    v1.push_back("world");
    v1.push_back("cpp");
    printStrVec(v1, "v1");

    cout << "\n=== Test 2: copy constructor ===\n";
    StrVec v2 = v1;  // 拷贝构造
    printStrVec(v2, "v2");
    v2.push_back("!!!");
    cout << "After modifying v2:\n";
    printStrVec(v1, "v1");
    printStrVec(v2, "v2");

    cout << "\n=== Test 3: copy assignment ===\n";
    StrVec v3;
    v3 = v1;  // 拷贝赋值
    printStrVec(v3, "v3");

    cout << "\n=== Test 4: move constructor ===\n";
    StrVec v4 = std::move(v1);  // 移动构造
    printStrVec(v4, "v4");

    cout << "\n=== Test 5: move assignment ===\n";
    StrVec v5;
    v5 = std::move(v4);  // 移动赋值
    printStrVec(v5, "v5");
    printStrVec(v4, "v4 (after move)");

    cout << "\n=== Test 6: reallocate check ===\n";
    StrVec v6;
    for (int i = 0; i < 10; ++i)
        v6.push_back("str" + to_string(i));
    printStrVec(v6, "v6");

    cout << "\n=== All tests done (check destructor output / valgrind) ===\n";
}
